package com.cn.wanxi.IO;

import com.cn.wanxi.IOModel.NewsModelIO;
import com.cn.wanxi.util.Tool;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;

public class NewsIO {


    public void writeNote(String path) {
        File file = new File(path);
        try {
            file.createNewFile();
            OutputStream outputStream = new FileOutputStream(file);
            NewsModelIO newsModelIO = new NewsModelIO();
            String[] hrefs = newsModelIO.getHrefForNews();
            String[] titles = newsModelIO.getTitleForNews();
            String[] createTimes = newsModelIO.getCreateTimeForNews();
            String hrefsString = Arrays.toString(hrefs);
            String titlesString = Arrays.toString(titles);
            String createTimesString = Arrays.toString(createTimes);

            outputStream.write(hrefsString.getBytes());
            outputStream.write(Tool.split.getPath().getBytes());
            outputStream.write(titlesString.getBytes());
            outputStream.write(Tool.split.getPath().getBytes());
            outputStream.write(createTimesString.getBytes());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void writeNoteForHome(String path) {
        File file = new File(path);
        try {
            file.createNewFile();
            OutputStream outputStream = new FileOutputStream(file);
            NewsModelIO newsModelIO = new NewsModelIO();

            outputStream.write(Arrays.toString(newsModelIO.getTitlesForHome()).getBytes());
            outputStream.write(Tool.split.getPath().getBytes());
            outputStream.write(Arrays.toString(newsModelIO.getContentForHome()).getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
